package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Children;
import org.hxyjs.entity.Clazz;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ClazzService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/clazzController")
public class ClazzController {
	@Resource
	ClazzService clazzService;
	@RequestMapping("/getAllClazz")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Clazz> getAllClazz() throws Exception {
    	System.out.println("查询全部班级");
		return clazzService.getAllClazzs();
    }

	@RequestMapping("/deleteClazzByClno/{clno}")
	@ResponseBody
    public DTO<Clazz> deleteClazzByClno(@PathVariable("clno") String clno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(clno+"删除班级");
    	return clazzService.deleteClazzByClno(clno);
    }

	@RequestMapping("/updateClazzByClno")
	@ResponseBody
	public DTO<Clazz> updateClazzByClno(@RequestBody Clazz clazz) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改班级");
		return clazzService.updateClazzByClno(clazz);
	}


	@RequestMapping("/addClazz")
	@ResponseBody
	public DTO<Clazz> addClazz(@RequestBody Clazz clazz) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加班级");
		System.out.println(clazz);
 		return clazzService.addClazz(clazz);
	}
	@RequestMapping("/getClazzByPage")
	@ResponseBody
	public DTO<Clazz> getClazzByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页班级");
		return clazzService.getClazzByPage(pageInfo);
	}

}